/**
 * 会员管理相关API服务
 * 包括获取会员计划、会员状态、升级会员等功能
 */
import api from './api';

const MembershipService = {
  /**
   * 获取所有可用的会员计划信息
   * @return {Promise} 会员计划信息Promise
   */
  getMembershipPlans: async () => {
    return await api.get('/api/membership/plans');
  },

  /**
   * 获取当前登录用户的会员状态
   * @return {Promise} 会员状态Promise
   */
  getMembershipStatus: async () => {
    return await api.get('/api/membership/status');
  },

  /**
   * 升级到专业版会员
   * @param {Object} upgradeData - 升级数据
   * @param {string} upgradeData.planId - 计划ID
   * @param {string} upgradeData.paymentMethod - 支付方式
   * @param {string} upgradeData.orderId - 订单ID
   * @return {Promise} 升级结果Promise
   */
  upgradeMembership: async (upgradeData) => {
    return await api.post('/api/membership/upgrade', upgradeData);
  },

  /**
   * 取消专业版会员资格
   * @return {Promise} 取消结果Promise
   */
  cancelMembership: async () => {
    return await api.post('/api/membership/cancel');
  },

  /**
   * 获取用户的会员购买交易记录
   * @param {Object} params - 查询参数
   * @param {number} [params.page=1] - 页码
   * @param {number} [params.limit=10] - 每页记录数
   * @return {Promise} 交易记录Promise
   */
  getTransactions: async (params = { page: 1, limit: 10 }) => {
    return await api.get('/api/membership/transactions', { params });
  }
};

export default MembershipService; 